package cqrtplm.controller;

import cqrtplm.constant.RouteConstant;
import cqrtplm.service.IRtCfgSerialNumberService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 流水号规则Controller
 * @author zhengxiong.jiang
 * @date 2023-02-16
 */
@RestController
@RequestMapping(RouteConstant.NUMBER + "v1")
public class RtCfgSerialNumberController {

    @Resource
    private IRtCfgSerialNumberService iRtCfgSerialNumberService;

    @ApiOperation(value = "根据单据前缀按日期生成流水号")
    @RequestMapping(value = "/take/{prefix}", method = RequestMethod.GET)
    public String getSerialNumber(@PathVariable String prefix) {
        return iRtCfgSerialNumberService.getSerialNumber(prefix);
    }

    @ApiOperation(value = "根据单据前缀生成流水号")
    @RequestMapping(value = "/take/{prefix}/{length}", method = RequestMethod.GET)
    public String getShortSerialNumber(@PathVariable String prefix, @PathVariable Integer length) {
        return iRtCfgSerialNumberService.getSerialNumber(prefix, length);
    }


}
